//
//  ReminderSettingViewController.m
//  rrqs
//
//  Created by mac book on 2019/4/30.
//

#import "ReminderSettingViewController.h"

@interface ReminderSettingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong) NSArray *dataArray;
@property (strong, nonatomic) NSDictionary *dataDic;

@property (strong, nonatomic) NSString *messageStatus;
@property (strong, nonatomic) NSString *phoneStatus;


@end

@implementation ReminderSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.messageStatus = @"";
    self.phoneStatus = @"";
    
    
    self.title = @"提示设置";
    
    [self creatTableView];
    
    
//    [self getdata];
    
}
- (void)getdata{
    
    NSDictionary* arg = @{@"ince":@"get_emp_info",@"emp_id":self.Identity.userInfo.userID};
    
    [DBNet PostURL:kHost parameters:arg succeed:^(NSDictionary *data) {
        [WMHelper outPutJsonString:data];
        NSInteger flag = [[data objectForKey:@"status"]integerValue];
        if(flag == 1){
            
            self.dataDic = [data objectForKey:@"info"];
            [self.tableView reloadData];
            
            
        }else{
            [self alertHUD:[data objectForKey:@"fail"]];
        }
       
        
    } failure:^(NSError *error) {
        [self alertHUD:@"网络异常"];
    }];
    
    
    
}


-(void)creatTableView{
    
    float table_h = SCREEN_HEIGHT - SafeAreaTopHeight;
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, table_h) style:UITableViewStyleGrouped];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:self.tableView];
    self.tableView.separatorColor = [UIColor groupTableViewBackgroundColor];
    
    if (@available(iOS 11.0, *))
    {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        self.tableView.estimatedRowHeight = 0;
        self.tableView.estimatedSectionFooterHeight = 0;
        self.tableView.estimatedSectionHeaderHeight = 0;
    }
    
}
#pragma mark 提交按钮

#pragma mark - tableview
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

//tableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 2;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellID = @"CELLID";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:cellID];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    UISwitch *messageSwitch = [[UISwitch alloc]init];
    [cell.contentView addSubview:messageSwitch];
    messageSwitch.backgroundColor = [UIColor lightGrayColor];
    messageSwitch.tintColor = [UIColor lightGrayColor];
    messageSwitch.layer.masksToBounds = YES;
    messageSwitch.layer.cornerRadius = 30/2;
    [messageSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(30);
        make.right.equalTo(cell.contentView).mas_offset(-20);
        make.centerY.equalTo(cell.contentView);
        make.width.mas_equalTo(50);
        
    }];

    
    
    if (indexPath.row == 0) {
        
        cell.textLabel.text = @"铃声";
        NSString *status = [NSString stringWithFormat:@"%@",self.dataDic[@"msgStatus"]];
        
        
        if ([status integerValue] == 2) {
            [messageSwitch setOn:YES];
            
        }else{
            [messageSwitch setOn:NO];
            
        }
        
    }else{
        
        cell.textLabel.text = @"震动";
        NSString *status = [NSString stringWithFormat:@"%@",self.dataDic[@"noticeStatus"]];
        
        if ([status integerValue] == 2) {
            [messageSwitch setOn:YES];
            
        }else{
            [messageSwitch setOn:NO];
            
        }
    }
    messageSwitch.tag = indexPath.row;
    
    [messageSwitch addTarget:self action:@selector(changeAllowStatus:) forControlEvents:UIControlEventValueChanged];
    
    return cell;
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView *headerView = [[UIView alloc] init];
    return headerView;
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    
    return 0.001;
    
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *footerView = [[UIView alloc] init];
    return footerView;
    
}

- (void)changeAllowStatus:(UISwitch *)switchBtn{
    
    if (switchBtn.tag == 0) {//消息通知
        if (switchBtn.isOn) {
            self.messageStatus = @"2";
        }else{
            self.messageStatus = @"1";
        }
    }else{
        if (switchBtn.isOn) {
            self.phoneStatus = @"2";
        }else{
            self.phoneStatus = @"1";
        }
    }
    
//    [self getdata];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
